package com.ruoyi.common.core.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("响应状态")
@Data
public class CommonResult<T> {

    /**
     * 状态码 1成功 0失败
     */
    @ApiModelProperty("状态码 200成功 500失败")
    private Integer code;
    /**
     * 后台返回给前端的数据
     */
    @ApiModelProperty("返回的数据")
    private T data;
    /**
     * 后台返回前端的提示信息
     */
    @ApiModelProperty("提示信息")
    private String msg;

    public static CommonResult success() {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CommonConstants.SUCCESS);
        return commonResult;
    }

    public static CommonResult success(Object data) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CommonConstants.SUCCESS);
        commonResult.setData(data);
        return commonResult;
    }

    public static CommonResult error(String msg) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CommonConstants.ERROR);
        commonResult.setMsg(msg);
        return commonResult;
    }
}